<?php
class CmsPostListControl extends CmsBaseControl
{
    public function Render()
    {
        $tagId = RequestHandler::Get('tag');
        $posts = CmsPostModel::GetInstance()->GetByTagId($tagId);
        $this->Repeat('post', $posts, array($this, 'FormatCallback'));
        return parent::Render();
    }

    public function FormatCallback($item)
    {
        $item = CmsPostModel::GetInstance()->FindById($item['id']);
        $item['authorName'] = CmsPostViewControl::GetAuthorName($item['createdby']);
        $item['publishedDate'] = CmsPostListControl::GetPublishedDate($item['datecreated']);
        return $item;
    }

    public static function GetPublishedDate($date)
    {
        return DatetimeBase::GetRelativeTime($date);
    }
}
?>